import React, { useState } from 'react'
import { StyleSheet, View, Text, Image, TouchableOpacity } from 'react-native';
import { AntDesign } from '@expo/vector-icons';
import '../global';
import Gear from './Gear';
import Kitchen from './Kitchen';
import Bed from './Bed';
import Introduce from './Introduce';

const Home = () => {
  const [show, setShow] = useState(<Introduce />);
  const [selectBtn, setSelectBtn] = React.useState(1);
  return (
    <View style={styles.container}>
      <View style={styles.title}>
        <View style={styles.logo}>
          <Image source={require('../assets/FinalWork/logo.png')} />
        </View>
        <View>
          <AntDesign name="search1" size={32} color="black" />
        </View>
      </View>
      <View style={styles.nav}>
        <TouchableOpacity
          style={[
            styles.navBox,
            { borderBottomColor: selectBtn === 1 ? '#ffdb2c' : '#fff' },
          ]}
          onPress={() => {
            setShow(<Introduce />);
            setSelectBtn(1);
          }}
        >
          <Text style={styles.navText}>推荐</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={[
            styles.navBox,
            { borderBottomColor: selectBtn === 2 ? '#ffdb2c' : '#fff' },
          ]}
          onPress={() => {
            setShow(<Gear />);
            setSelectBtn(2);
          }}
        >
          <Text style={styles.navText}>家居</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={[
            styles.navBox,
            { borderBottomColor: selectBtn === 3 ? '#ffdb2c' : '#fff' },
          ]}
          onPress={() => {
            setShow(<Kitchen />);
            setSelectBtn(3);
          }}
        >
          <Text style={styles.navText}>餐厨</Text>
        </TouchableOpacity>
        <TouchableOpacity
          style={[
            styles.navBox,
            { borderBottomColor: selectBtn === 4 ? '#ffdb2c' : '#fff' },
          ]}
          onPress={() => {
            setShow(<Bed />);
            setSelectBtn(4);
          }}
        >
          <Text style={styles.navText}>床上用品</Text>
        </TouchableOpacity>
      </View>
      {show}
    </View >
  )
}
// style样式
const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
  },
  title: {
    height: 0.1 * h,
    backgroundColor: '#ffdb2c',
    flexDirection: 'row',
    alignItems: 'center'
  },
  logo: {
    width: 0.9 * w,
    justifyContent: 'center',
    paddingLeft: 0.45 * w
  },
  nav: {
    height: 0.06 * h,
    flexDirection: 'row',
  },
  navText: {
    color: '#535353',
    fontSize: 20,
  },
  navBox: {
    width: 0.25 * w,
    alignItems: 'center',
    justifyContent: 'space-around',
    borderBottomWidth: 5,
  }
})

export default Home;